package com.beiben.work.hours.controller;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.beiben.work.hours.domain.FileHours;
import com.beiben.work.hours.service.IFileHoursService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletRequest;

/**
 * 文件工时管理Controller
 * 
 * @author xgq
 * @date 2020-08-26
 */
@RestController
@RequestMapping("/work/hours")
public class FileHoursController extends BaseController
{
    @Autowired
    private IFileHoursService fileHoursService;

    /**
     * 查询文件工时管理列表
     */
    @PreAuthorize("@ss.hasPermi('work:hours:list')")
    @GetMapping("/list")
    public TableDataInfo list(FileHours fileHours)
    {
        startPage();
        List<FileHours> list = fileHoursService.selectFileHoursList(fileHours);
        return getDataTable(list);
    }

    /**
     * 导出文件工时管理列表
     */
    @PreAuthorize("@ss.hasPermi('work:hours:export')")
    @Log(title = "文件工时管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FileHours fileHours)
    {
        List<FileHours> list = fileHoursService.selectFileHoursList(fileHours);
        ExcelUtil<FileHours> util = new ExcelUtil<FileHours>(FileHours.class);
        return util.exportExcel(list, "hours");
    }

    /**
     * 获取文件工时管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:hours:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put(AjaxResult.DATA_TAG,fileHoursService.selectFileHoursById(fileId));
        if (StringUtils.isNotNull(fileId))
        {
            ajax.put("deptIds",fileHoursService.selectFileHoursDeptByfileId(fileId));
        }
        return ajax;
    }

    /**
     * 新增文件工时管理
     */
    @PreAuthorize("@ss.hasPermi('work:hours:add')")
    @Log(title = "文件工时管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileHours fileHours)
    {
        return toAjax(fileHoursService.insertFileHours(fileHours));
    }

    /**
     * 修改文件工时管理
     */
    @PreAuthorize("@ss.hasPermi('work:hours:edit')")
    @Log(title = "文件工时管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileHours fileHours)
    {
        return toAjax(fileHoursService.updateFileHours(fileHours));
    }

    /**
     * 删除文件工时管理
     */
    @PreAuthorize("@ss.hasPermi('work:hours:remove')")
    @Log(title = "文件工时管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(fileHoursService.deleteFileHoursByIds(fileIds));
    }

    /**
     * 查询文件工时管理列表
     */
    @GetMapping("/alllist")
    public AjaxResult allList(FileHours fileHours)
    {
        List<FileHours> data = fileHoursService.selectFileHoursList(fileHours);
        return AjaxResult.success(data);
    }

    /**
     * 查询文件工时管理列表
     */
    @PostMapping("/deptList")
    public AjaxResult deptHoursList(@RequestBody FileHours fileHours)
    {
        List<FileHours> data = fileHoursService.selectFileHoursDeptList(fileHours);
        return AjaxResult.success(data);
    }

}
